/*
Hermes Core: General Purpose Mobile Agent Platform
Copyright (C) 2006 UNICAM - Università degli Studi di Camerino

Group leaders: Flavio Corradini and Emanuela Merelli

Developers: Ezio Bartocci, Diego Bonura, Rosario Culmone,
Davide Lorenzoli, Leonardo Mariani, Francesca Piersigilli, 
Lorenzo Scortichini, Leonardo Vito.

GNU Lesser Public License

This library is free software; you can redistribute it 
and/or modify it under the terms of the GNU Lesser General 
Public License as published by the Free Software Foundation, 
version 2.1 of the License.

This library is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
See the GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public 
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.

Emanuela Merelli
Dipartimento di Matematica ed Informatica
Università di Camerino
via Madonna delle Carceri, 62032 Camerino, Italy
E.Mail: emanuela.merelli@unicam.it
*/
package hermesV2.services.HubService;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import java.util.Properties;


/**
 * Manages the load and check of the file properties
 *
 * @author Davide Lorenzoli
 * @author Diego Bonura
 */
public class LoadProperties {
	   /**
	    * Loads the property file of the Jawe service agent.
	    *
	    * @param propertyFileName The name of the property file
	    * @param hermesHome The home directory of the hermes platform.
	    * @return The property loaded.
	    * @throws Exception If some property is malformed or missed
	    */
	   public static Properties loadProperty(String propertyFileName,String hermesHome)
	           throws Exception {
	       Properties p = new Properties();
	       //I'm going to load my property file
	       InputStream fis = new FileInputStream(propertyFileName);
	       p.load(fis);
	       /* Checks the smtp property */

	       if (p.getProperty("HERMESV2.HUB") == null) {
	           throw new Exception(
	                   "PEER.TYPE property doesn't exist in the property file:"
	                           + propertyFileName);
	       }else if (p.getProperty("HERMESV2HUB.IP") == null) {
	           throw new Exception(
	                   "HERMESV2HUB.IP property doesn't exist in the property file:"
	                           + propertyFileName);
	       }else if (p.getProperty("HERMESV2HUB.PORT") == null) {
	           throw new Exception(
	                   "HERMESV2HUB.PORT property doesn't exist in the property file:"
	                           + propertyFileName);
	       }
	       return p;
	   }
}
